var provinceName = '上海市';
var districtName = '市辖区';
var etWebSiteUrl = "http://www.jd100.com";

function init(){
	//初始化校验控件
	$("form").validationEngine({
		validationEventTrigger:"",
		inlineValidation: true, 
		scroll : true,
		focusFirstField : true,
		promptPosition : "topRight"
	});
	
	//头部菜单初始化
	headInit(1,0);
	//内容体初始化
	contentInit();
	
}

/**内容体初始化 */
function contentInit(){
	//标题修改 微信分享用
	 var urlType= $.url().param("urlType");
	 if(typeof(urlType) != "undefined"&&urlType==="3"){
		$("title").html("测一测高考志愿和适合自己的专业——免费志愿填报工具");
	 }
	//内容添加添加 
    $.ajax({
        url:'evr_score_estimate_make_pick.html',
        type:'get',
        dataType:'html',
        async: false,
        success:function (data){
            $(".page-box").append(data); //填充到页面内容区
        }
    });
    //新增一个判断 用户是否是其他用户登录
    $.ajax({
    	url:'../../markposition/isOtherUserLogin',
    	type:'post',
    	dataType:'json',
    	async:false,
    	success:function(data){
    		if(data.success){
    			if(data.code==0){
    				//若是 b用户登录的话 ，清空session中的临时表id，刷新界面
    				location.href="evr_score_estimate.html";
    			}else{
    				//内容初始化
    			    $.ajax({
    			        url: '../../markposition/getevrwriteinfotemp',
    			        type: 'post',
    			        dataType: 'json',
    			        async: false,
    			        data: {},
    			        success: function (result) {
    			        	if(result[0]){
    			        		$("#school").val(result[0].schoolName);
    			            	$('input:radio[name="optionsRadios"][value="'+result[0].grade +'"]').prop('checked', true);
    			        		$('input:radio[name="optionsRadios1"][value="'+result[0].wllx +'"]').prop('checked', true);
    			        		$("#schoolId").val(result[0].middleSchoolId);
    			        		$("#areaid").val(result[0].schoolAreaId);
    			        		//只是用来计算地区分类 
    			        		$("#iprovince").val(result[2]);
    			        	}
    			        	
    			        }
    			    });
    			}
    		}else{
    			$.common.alert.error("加载失败!");
    		}
    	}
    });
    
}


$(function(){
	init();
	
	
	 
	 ///////////////////////////////////事件区域
	 //中学选择控件
	 $("#school").click(function() {
	        $("#school").blur();
	        popwindow_show("j_schooldisplay", 800, 660, "", function() {new schoolView()});

	 });
	 
	 $("#submit").click(function(){
		 //表单验证
		 if(!$('#form').validationEngine('validate')){
			 $(".formError ").delegate(this,"click",function(){
				 $(this).remove();
			 });
			 return false;
		}
		
		var schoolName = $("#school").val();
		var grade  = $("input[name='optionsRadios']:checked").val();
		var wllx = $("input[name='optionsRadios1']:checked").val();
		var schoolId =  $("#schoolId").val();
		if(!schoolId){
			schoolId = -1;//没有学校
		}
		var areaId = $("#areaid").val();
		var provinceName = $("#iprovince").val();
		var data = {};
		data.schoolName = schoolName;
		data.grade = grade;
		data.wllx = wllx;
		data.schoolId = schoolId;
		data.areaId = areaId;
		data.provinceName = provinceName;
		$.ajax({
            url: '../../markposition/beginningpagesave',
            type: 'post',
            dataType: 'json',
            async: false,
            data: data,
            success: function (result) {
            	 if(result.success){
            		 var urlType= $.url().param("urlType");
            		 if(typeof(urlType) != "undefined"&&urlType==="3"){
            			 location.href="evr_diag.html";
            		 }else{
            			 location.href="evr_volunte_analysis.html";
            		 }
            		 
            	 }else{
            		 $.common.alert.error("操作失败!");
            	 }
            }
        });
		
	 })
});


///////////////////////////////方法区
/**表单自定义验证*/
function validateSchoolName(){
	if($("#school").val() == "点击选择学校"){
		return "请选择学校";
	}else{
		return ;
	}
	
}

